package com.qmerak.service;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @author shaohong.cheng
 * @date 2013-4-12
 */
public abstract class AbstractService<E> {
	protected void merge(E o, E n) {
		Field[] fields = o.getClass().getDeclaredFields();
		for (Field field : fields) {
			if(Modifier.isPrivate(field.getModifiers())){
				field.setAccessible(true);
			}
			String fieldName = field.getName();
			String fieldValue = null;
			try {
				fieldValue = String.valueOf(field.get(n));
			} catch (IllegalArgumentException e1) {
				e1.printStackTrace();
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			}
			System.out.println(fieldName + ":" + fieldValue);
			Method getMethod = null;
			try {
				getMethod = n.getClass().getMethod("get" + fieldName, field.getDeclaringClass());
			} catch (NoSuchMethodException e) {
			} catch (SecurityException e) {
			}
			if (getMethod == null) {
				String fieldName1 = fieldName.replaceFirst(fieldName.substring(0, 1), fieldName.substring(0, 1).toUpperCase());
				try {
					getMethod = n.getClass().getMethod("get" + fieldName1, field.getDeclaringClass());
				} catch (NoSuchMethodException e) {
				} catch (SecurityException e) {
				}
			}
			if (getMethod == null) {

			}

		}
	}

}
